<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of recursos_controller
 *
 * @author felipe
 */
class RecursosController extends AppController {

    public $name = 'Recursos';
    public $uses = array('Recurso', 'Proveedor', 'Producto', 'MedioPago');

    function index() {
        $recursos = $this->paginate('Recurso');
$this->set(compact('recursos'));
    }

    function ver($id = null) {
        $this->Recurso->id = $id;
        $this->set('recurso', $this->Recurso->read());
        $this->set('id', $id);
    }

    function agregar() {
        if (!empty($this->data)) {
            if ($this->Recurso->save($this->data)) {
                $this->Session->setFlash('Recurso ingresado correctamente');
                $this->redirect(array('action' => 'index'));
            }
        }
        $producto = $this->Recurso->Producto->find('list', array('fields' => array('id', 'nombre')));
        $this->set(compact('producto'));
        $proveedor = $this->Recurso->Proveedor->find('list', array('fields' => array('id', 'nombre')));
        $this->set(compact('proveedor'));
        $medio_pago = $this->Recurso->MedioPago->find('list', array('fields' => array('id', 'nombre')));
        $this->set(compact('medio_pago'));
    }

    function borrar($id) {
        if ($this->Recurso->delete($id)) {
            $this->Session->setFlash('Recurso eliminado exitosamente');
            $this->redirect(array('action' => 'index'));
        }
    }

    function editar($id) {
        $this->Recurso->id = $id;
        if (empty($this->data)) {
            $this->data = $this->Recurso->read();
            $producto = $this->Recurso->Producto->find('list', array('fields' => array('id', 'nombre')));
            $this->set(compact('producto'));
            $proveedor = $this->Recurso->Proveedor->find('list', array('fields' => array('id', 'nombre')));
            $this->set(compact('proveedor'));
            $medio_pago = $this->Recurso->MedioPago->find('list', array('fields' => array('id', 'nombre')));
            $this->set(compact('medio_pago'));
            $this->set('id', $id);
        } else {
            if ($this->Recurso->save($this->data)) {
                $this->Session->setFlash('Recurso editado exitosamente');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

}

?>
